using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace BinaryComponents.SuperList
{
    public class ColumnTextProperty : Attribute
    {
        public string Name;

        public static string GetPropertyTextValue(Type typeInfo, string fieldName)
        {
            string returnValue = "";

            PropertyInfo[] propInfos = typeInfo.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo prop in propInfos)
            {
                if (prop.Name == fieldName)
                {
                    object[] attributes;
                    attributes = prop.GetCustomAttributes(true);
                    foreach (Attribute attr in attributes)
                    {
                        if (attr is ColumnTextProperty)
                        {
                            returnValue = ((ColumnTextProperty)attr).Name;
                        }
                    }
                }
            }

            return returnValue;
        }

        public static string GetPropertyTextValue(object theObject, string fieldName)
        {
            string returnValue = "";

            MemberInfo membInfo;
            membInfo = theObject.GetType();
            PropertyInfo[] propInfos = theObject.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo prop in propInfos)
            {
                if (prop.Name == fieldName)
                {
                    object[] attributes;
                    attributes = prop.GetCustomAttributes(true);
                    foreach (Attribute attr in attributes)
                    {
                        if (attr is ColumnTextProperty)
                        {
                            returnValue = ((ColumnTextProperty)attr).Name;
                        }
                    }
                }
            }

            return returnValue;
        }
    }
}
